#ifndef __FISH_GROUP_H__
#define __FISH_GROUP_H__
#include <vector>
#include "../tinyxml/tinyxml.h"
#include "cocos2d.h"
namespace fishingjoy
{
	namespace config
	{
		struct SFishInGroup
		{
			int FID;
			int OffsetX;
			int OffsetY;
		};
		struct SFishGroupData
		{
			int GID;
			int AnchorX;
			int AnchorY;
			int X;
			int Y;
			int TargetX;
			int TargetY;
			int Speed;
			int BeginTime;
			int LastTime;
			std::vector<SFishInGroup> Fishs;
		};
		class CFishGroup
		{
			static std::vector<SFishGroupData> m_vecFishData;
			static void load()
			{
				if(m_vecFishData.size()==0){
					TiXmlDocument doc;
					std::string pathKey = "config/fishgroups.xml"; 
					pathKey = cocos2d::CCFileUtils::sharedFileUtils()->fullPathForFilename(pathKey.c_str());	
					if(doc.LoadFile(pathKey.c_str())){
						TiXmlElement* root = doc.RootElement();
						if(root){
							TiXmlElement* pGroupNode = root->FirstChildElement();
							while(pGroupNode){
								m_vecFishData.push_back(SFishGroupData());
								SFishGroupData& gd = m_vecFishData[m_vecFishData.size()-1];
								gd.GID = atoi(pGroupNode->Attribute("gid"));
								gd.AnchorX = atoi(pGroupNode->Attribute("anchorx"));
								gd.AnchorY = atoi(pGroupNode->Attribute("anchory"));
								gd.X = atoi(pGroupNode->Attribute("x"));
								gd.Y = atoi(pGroupNode->Attribute("y"));
								gd.TargetX = atoi(pGroupNode->Attribute("tx"));
								gd.TargetY = atoi(pGroupNode->Attribute("ty"));
								gd.Speed = atoi(pGroupNode->Attribute("speed"));
								gd.BeginTime = atoi(pGroupNode->Attribute("appear"));
								gd.LastTime = atoi(pGroupNode->Attribute("last"));
								
								TiXmlElement* pNode = pGroupNode->FirstChildElement();
								while(pNode){
									gd.Fishs.push_back(SFishInGroup());
									SFishInGroup& rFG = gd.Fishs[gd.Fishs.size()-1];
									rFG.FID = atoi(pNode->Attribute("fid"));
									rFG.OffsetX = atoi(pNode->Attribute("ox"));
									rFG.OffsetY = atoi(pNode->Attribute("oy"));
									pNode = pNode->NextSiblingElement();
								}
								pGroupNode = pGroupNode->NextSiblingElement();
							}
						}
					}
				}
			}
		public:
			static const std::vector<SFishGroupData>& getGroupData()
			{
				load();
				return m_vecFishData;
			}
		};
	}
}

#endif